package com.itheima.controller;

import com.itheima.pojo.PageBean;
import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.servise.StudentServise;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentServise studentServise;

    //学员列表查询
    @GetMapping
    public Result list(StudentQueryParam param) {
        PageBean list = studentServise.list(param);
        return Result.success(list);
    }
    //添加学员
    @PostMapping
    public Result add(@RequestBody Student student) {
        studentServise.add(student);
        return Result.success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        Student student = studentServise.getById(id);
        return Result.success(student);
    }
    //修改学员信息
    @PutMapping
    public Result update(@RequestBody Student student) {
        studentServise.putStudent(student);
        return Result.success();
    }
    //删除学员
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable String ids) {
        String[] split = ids.split(",");
        studentServise.delete(split);
        return Result.success();
    }
    //违纪处理
    @PutMapping("/violation/{id}/{score}")
    public Result violation(@PathVariable Integer id,@PathVariable Short score) {
        studentServise.violation(id, score);
        return Result.success();
    }


}
